<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<jsp:include page="../pageheader.jsp"/>

<div class="container">
    <div class="jumbotron">

        <div class="row">
            <div class="col-xs-9">
                <h1>${topic.getTitle()}</h1>
            </div>
            <div class="col-xs-3">
                ${topic.getCreatedDate()}
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                ${topic.getMessage()}
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                ${topic.getUser().getName()}
            </div>
        </div>
    </div>

    <div id="postsDiv" >   
        <c:if test="${posts != null}">
            <c:forEach items="${posts}" var="post">
                <div class="well well-lg">
                    <div class="row">
                        <div class="col-xs-9">
                            ${post.getMessage()}
                        </div>
                        <div class="col-xs-3">
                            ${post.getCreatedDate()}
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-12">
                            ${post.getUser().getName()}
                        </div>
                    </div>
                </div>
            </c:forEach>
        </c:if>
    </div>

    <c:if test="${!isAdmin}">
        <form class="form-horizontal">
            <div class="form-group ">
                <div class="col-xs-12">
                    <textarea class="form-control input-sm" id="answerField" placeholder="New answer"></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-12">
                    <button type="button" onclick="addNewTopicClick()" class="btn btn-primary">Add new answer</button>
                </div>
            </div>
        </form>
    </c:if>
</div>

<script>
    var topic_id = ${topic.getId()};
</script>

<jsp:include page="../pagefooter.jsp"/>
